#include "stdafx.h"
#include "3In10Operation.h"

void ThreeDOperation::searchListOperation(int i,int j, int k, list<SearchItem> &searchList){

	list<SearchItem>::iterator iter;

	bool in = false;

	for(iter = searchList.begin();iter !=searchList.end();++iter){
		if((*iter).isIn(i,j,k)){
			(*iter).count += 1;
			in = true;
			break;
		}
	}
	if(in == false){
		SearchItem *s = new SearchItem(i,j,k,1);
		searchList.push_back(*s);
		delete s;
	}
}

void ThreeDOperation::combListOperation(int i,int j, int k,list<Combination>&combList,int type){
	list<Combination>::iterator iter;

	bool b = false;

	for (iter = combList.begin(); iter!= combList.end();++iter){
		if(type == 1)
			b = (*iter).isIn(i,j,k);
		else if (type == 2)
			b = (*iter).isIn2(i,j,k);
		else if (type == 3)
			b = (*iter).isIn3(i,j,k);
		else if (type == 4)
			b = (*iter).isIn4(j,k);
		else if (type == 41)
			b = (*iter).isIn41(j,k);

		if(b)
			(*iter).count = 0;
		else
			(*iter).count = (*iter).count + 1;
	}
}

void ThreeDOperation::makeMatchListOperation(list<Combination> &list1,list<Combination> &list2, int type){
	if (type == 2)
		list2 = list1;
	for(list<Combination>::iterator iter1=list1.begin();iter1!=list1.end();++iter1){
		for(list<Combination>::iterator iter2=list2.begin();iter2!=list2.end();++iter2){
			if((*iter1).matchFour((*iter2))){
				if (type == 1)
					(*iter1).match4list.push_back(*iter2);
				else if(type == 2)
					(*iter1).match4listSelf.push_back(*iter2);
			}
		}		
	}
}